package com.xiao.controller;

import com.xiao.domain.ResponseResult;
import com.xiao.domain.dto.AddLinkDto;
import com.xiao.domain.dto.ChangeLinkStatusDto;
import com.xiao.domain.dto.LinkDto;
import com.xiao.domain.dto.SaveUpdateLinkDto;
import com.xiao.service.impl.BlogLinkServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/content/link")
@Api(tags = "友链")
public class BlogLinkController  {

    @Autowired
    BlogLinkServiceImpl  blogLinkService;

    @GetMapping("/list")
    @ApiOperation("获取所有的友链列表 ，分页形式展示，并支持模糊搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页码"),
            @ApiImplicitParam(name = "pageSize",value = "页面大小"),
            @ApiImplicitParam(name = "linkDto",value = "查询Dto")
    })
    public ResponseResult getLinkList(Integer pageNum, Integer pageSize, LinkDto linkDto){
        ResponseResult linkList = blogLinkService.getLinkList(pageNum,pageSize,linkDto);
        return  linkList;
    }

    @PostMapping
    @ApiOperation("新增友链")
    @ApiImplicitParam(name = "addLinkDto",value = "新增友链-Dto")
    public ResponseResult AddLink(@RequestBody  AddLinkDto addLinkDto){ // 表明参数来自请求体 application/json 不能忘记！！！
        ResponseResult responseResult = blogLinkService.AddLink(addLinkDto);
        return responseResult;
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id，查询友链")
    @ApiImplicitParam(name = "id",value = "友链ID")
    public ResponseResult getLinkById(@PathVariable("id") Long id){
        ResponseResult responseResult = blogLinkService.getLinkById(id);
        return responseResult;
    }


    @PutMapping
    @ApiOperation("根据提交的数据，保存修改友链")
    @ApiImplicitParam(name = "saveUpdateLinkDto",value = "提交需要修改的友链dto")
    public ResponseResult saveUpdateLink(@RequestBody SaveUpdateLinkDto saveUpdateLinkDto){

        ResponseResult responseResult = blogLinkService.saveUpdateLink(saveUpdateLinkDto);

        return responseResult;
    }


    @DeleteMapping("/{id}")
    @ApiOperation("根据 id 列表,删除友链")
    @ApiImplicitParam(name = "idList",value = "被删除友链id列表")
    public ResponseResult delLinkByIdList(@PathVariable("id") List<Long> idList){
        ResponseResult responseResult = blogLinkService.delLinkByIdList(idList);
        return responseResult;
    }

    @PutMapping("/changeLinkStatus")
    @ApiOperation("根据 友链id,和状态编号,审批友链")
    @ApiImplicitParam(name ="changeLinkStatusDto" ,value = "接收参数-dto")
    public ResponseResult changeLinkStatus(@RequestBody ChangeLinkStatusDto changeLinkStatusDto){
        ResponseResult responseResult = blogLinkService.changeLinkStatus(changeLinkStatusDto);
        return responseResult;
    }

}
